import 'package:flutter/material.dart';

const cityNames = [
  '北京','南京','杭州','上海','深圳','广州','合肥','太原','济南','南昌','乌鲁木齐','沈阳','哈尔滨','长春'
];

class HorizontalListPage extends StatefulWidget {
  const HorizontalListPage({super.key});

  @override
  State<HorizontalListPage> createState() => _HorizontalListPageState();
}

class _HorizontalListPageState extends State<HorizontalListPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('下拉刷新数据')),
      body: SizedBox(
        height: 200,
        child: ListView(
          scrollDirection: Axis.horizontal,
          children: _buildList(),
        ),
      ),
    );
  }

  List<Widget> _buildList() {
    return cityNames.map((city) => _item(city)).toList();
  }
  Widget _item(String city) {
    return Container(
      width: 80, margin: const EdgeInsets.only(right: 5),alignment: Alignment.center,
      decoration: const BoxDecoration(color: Colors.amber),
      child: Text(city,style: TextStyle(color: Colors.white, fontSize: 20),),
    );
  }
}
